package thread_pool;

import java.util.Random;
import java.util.concurrent.*;

/**
 * Created with IDEA
 * author:ju bai
 * Date:2021/5/23
 * Time:10:58
 * submit执行方式
 **/
public class PoolDemo17 {
    public static void main(String[] args) throws ExecutionException, InterruptedException {

        ThreadPoolExecutor executor = new ThreadPoolExecutor(
                5, 5, 0,
                TimeUnit.SECONDS, new LinkedBlockingQueue<>(1000));

        //返回参数
        Future<Integer> future = executor.submit(new Callable<Integer>() {
            @Override
            public Integer call() throws Exception {
                int num = new Random().nextInt(10);
                System.out.println("线程池出现了随机数:"+num);
                return num;
            }
        });

        System.out.println("main 得到返回值:"+future.get());

    }

}
